{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Series中自带的interpolate值法\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from scipy.optimize import newton\n",
    "\n",
    "# 输入数据路径,需要使用Excel格式；\n",
    "inputfile = '../Data/missing_data.xls'\n",
    "# 输出数据路径,需要使用Excel格式\n",
    "outputfile = '../Data/Temp/series_missing_data_processed.xls'\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(5, 0), (12, 0), (3, 1), (10, 1), (19, 1), (20, 1), (4, 2), (7, 2), (10, 2), (16, 2)]\n"
     ]
    }
   ],
   "source": [
    "# 读入数据\n",
    "data = pd.read_excel(inputfile, header=None, names=['A', 'B', 'C'])\n",
    "# 判断DataFrame中空值的位置（行，列）\n",
    "NULL_value_position = []\n",
    "for j in range(len(data.columns)):\n",
    "    value_column = data[data.columns[j]].isnull()\n",
    "    for i in range(len(value_column)):\n",
    "        if value_column[i] == True:\n",
    "            NULL_value_position.append((i, j))\n",
    "print(NULL_value_position)\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "# 利用pandas中interpolate进行缺失值的补充\n",
    "data = data.interpolate()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "            A          B          C\n",
      "0   235.83330  324.03430  478.32310\n",
      "1   236.27080  325.63790  515.45640\n",
      "2   238.05210  328.08970  517.09090\n",
      "3   235.90630  298.46105  514.89000\n",
      "4   236.76040  268.83240  500.49060\n",
      "5   237.08855  404.04800  486.09120\n",
      "6   237.41670  391.26520  516.23300\n",
      "7   238.65630  380.82410  475.79190\n",
      "8   237.60420  388.02300  435.35080\n",
      "9   238.03130  206.43490  487.67500\n",
      "10  235.07290  303.25680  573.95485\n",
      "11  235.53130  400.07870  660.23470\n",
      "12  235.00005  411.20690  621.23460\n",
      "13  234.46880  395.23430  611.34080\n",
      "14  235.50000  344.82210  643.08630\n",
      "15  235.63540  385.64320  642.34820\n",
      "16  234.55210  401.62340  622.64145\n",
      "17  236.00000  409.64890  602.93470\n",
      "18  235.23960  416.87950  589.34570\n",
      "19  235.48960  416.87950  556.34520\n",
      "20  236.96880  416.87950  538.34700\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\electric-leak-recognition\\venv\\lib\\site-packages\\ipykernel_launcher.py:3: FutureWarning: As the xlwt package is no longer maintained, the xlwt engine will be removed in a future version of pandas. This is the only engine in pandas that supports writing in the xls format. Install openpyxl and write to an xlsx file instead. You can set the option io.excel.xls.writer to 'xlwt' to silence this warning. While this option is deprecated and will also raise a warning, it can be globally set and the warning suppressed.\n",
      "  This is separate from the ipykernel package so we can avoid doing imports until\n"
     ]
    }
   ],
   "source": [
    "# 输出结果\n",
    "print(data)\n",
    "data.to_excel(outputfile, header=None, index=False)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}